#!/bin/sh

template() {
	toy=$(echo "$1" | cut -d ';' -f 1)
	content=$(echo "$1" | cut -d ';' -f 2)
	cat <<EOF
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
EOF
	printf '\t\t<title>toymaker::%s</title>\n' "$toy"
	cat <<EOF
		<style>
			* {
				box-sizing: border-box;
			}
			a {
				color: #00afff;
			}
			a:hover {
				background-color: #db9d3b;
				color: #000000;
			}
		</style>
	</head>
	<body style="background-color: #292929; color: #fafafa;">
		<header style="font-size: 1.25rem; padding-top: .3125rem; padding-bottom: .3125rem;">
			<a href="/toys/" style="font-family: monospace; text-decoration: none;">toymaker</a>
		</header>
		<main style="margin-left: 1rem; margin-top: 2rem;">
EOF
	printf '\t\t\t<h1>%s</h1>\n' "$toy"
	if [ "$(echo "$content" | tr -d ' ' | sed 's/n,//')" = '' ]
	then
		printf '\t\t\t<span style="font-size: 2rem;>Have not run yet</span>\n'
	else
		printf '\t\t\t<ul>\n'
		for item in $content
		do
			status=$(echo "$item" | cut -d ',' -f1)
			name=$(echo "$item" | cut -d ',' -f2)
			printf '\t\t\t\t<li>\n'
			if [ "$status" = '0' ]
			then
				printf '\t\t\t\t\t<span style="color: #5af78e; font-size: .75rem; margin-right: .5rem;">OK</span>\n'
			elif [ "$status" = 'r' ]
			then
				printf '\t\t\t\t\t<span style="font-size: .75rem; margin-right: .5rem;">R_</span>\n'
			else
				printf '\t\t\t\t\t<span style="color: #ff5c57; font-size: .75rem; margin-right: .5rem;">ER</span>\n'
			fi
			printf '\t\t\t\t\t<a href="/toys/%s/%s"><span style="font-size: 1.5rem;">%s</span></a>\n' "$toy" "$name" "$name"
			printf '\t\t\t\t</li>\n'
		done
		printf '\t\t\t</ul>\n'
	fi
	cat <<EOF
		</main>
	</body>
</html>
EOF
}
